/*
 * @Author: liuxiao
 * @Date: 2023-12-12 23:02:59
 * @Last Modified by: liuxiao
 * @Last Modified time: 2023-12-13 22:51:00
 * @课程章节模型
 *
 */

const { DataTypes } = require('sequelize')

const seq = require('../db/seq')

const Chapter = seq.define('edu_chapter', {
  course_id: {
    type: DataTypes.INTEGER(11),
    allowNull: false,
    comment: '课程ID'
  },
  chapterName: {
    type: DataTypes.STRING(10),
    allowNull: false,
    comment: '章节名称'
  },
  description: {
    type: DataTypes.STRING(100),
    allowNull: true,
    comment: '章节描述'
  },
  sort: {
    type: DataTypes.INTEGER(10),
    allowNull: false,
    defaultValue: 0,
    comment: '排序字段'
  }
})

//force:true，强制创建，如果存在表，则删除
//Chapter.sync({ alter: true })
//Chapter.sync()
async function createChapter() {
  // await Chapter.sync() // 同步模型和数据库

  let data = [
    {
      course_id: 1,
      title: '第一章',
      sort: 0
    },
    {
      course_id: 1,
      title: '第二章',
      sort: 1
    },
    {
      course_id: 1,
      title: '第三章',
      sort: 2
    }
  ]

  //const createChapter = await Chapter.bulkCreate(data)

  // console.log(category.toJSON())
}

// createChapter().catch(console.error)

module.exports = Chapter
